#include <boost/interprocess/ipc/message_queue.hpp>
#include <iostream>
#include <vector>

int main ()
{
   try{
      //Open a message queue.
      boost::interprocess::message_queue mq
         (boost::interprocess::open_only        //only create
         ,"message_queue"  //name
         );

      unsigned int priority;
      std::size_t recvd_size;

	  std::cout << "get_max_msg(): " << mq.get_max_msg() << std::endl;
	  std::cout << "get_max_msg_size(): " << mq.get_max_msg_size() << std::endl;
	  std::cout << "get_num_msg(): " << mq.get_num_msg() << std::endl;

      //Receive 100 numbers
	  int sum = 0;
      for(int i = 0; i < 100; ++i){
         int number;
         mq.receive(&number, sizeof(number), recvd_size, priority);
         if(number != i || recvd_size != sizeof(number))
            return 1;
		 sum += number;
      }
	  std::cout << "received: " << 100 << " elements" << std::endl;
	  std::cout << "The sum is: " << sum << std::endl;
   }
   catch(boost::interprocess::interprocess_exception &ex){
      boost::interprocess::message_queue::remove("message_queue");
      std::cout << ex.what() << std::endl;
      return 1;
   }
   boost::interprocess::message_queue::remove("message_queue");
   return 0;
}